package org.voidness.squaretilesframework.server;

import org.voidness.squaretilesframework.Tile;

/** A class to represent a square tile */
public class ServerTile extends Tile {
    /** Whether this tile is walkable by players or not */
    private boolean walkable;

    /** The sprite occupying this tile */
    private ServerActor occupier = null;

    /**
     * A tile constructor.
     * 
     * @param mParent The parent map
     * @param mWalkable Whether this tile is walkable or not
     */
    public ServerTile(ServerMap mParent, boolean mWalkable) {
        super(-1, -1, mParent, mWalkable);
        walkable = mWalkable;
    }

    /**
     * (Re)defines the tile's occupier
     * 
     * @param mOccupier The occupier to set
     */
    public void setOccupier(ServerActor mOccupier) {
        if (walkable && occupier == null)
            occupier = mOccupier;
    }

    /**
     * Returns the current tile occupier
     * 
     * @return The tile's ServerActor
     */
    // TODO: Fix this.
    public ServerActor getServerOccupier() {
        return occupier;
    }

    /**
     * Clears any occupation from this tile
     */
    public void clearOccupation() {
        occupier = null;
    }

    /**
     * Returns whether this tile is walkable or not
     * 
     * @return True if so, false otherwise
     */
    public boolean isWalkable() {
        return walkable;
    }

    /**
     * Defines this tile as beeing walkable or not
     * 
     * @param mState True to set as walkable, false to set as not walkable
     */
    public void setWalkable(boolean mState) {
        walkable = mState;
    }

    /**
     * Returns whether this tile is occupied or not
     * 
     * @return True if it is, false otherwise
     */
    public boolean isOccupied() {
        return (occupier != null);
    }
}